package org.apache.flink.connector.scylladb.config;

import org.apache.flink.configuration.ConfigOption;
import org.apache.flink.configuration.ConfigOptions;

import java.time.Duration;

/**
 * ScyllaDB 连接器的配置选项定义
 */
public class ScyllaDBConfigOptions {

    // 连接相关配置
    public static final ConfigOption<String> URL = ConfigOptions
            .key("url")
            .stringType()
            .noDefaultValue()
            .withDescription("ScyllaDB 连接地址，格式为 host:port");

    public static final ConfigOption<String> KEY_SPACE = ConfigOptions
            .key("key-space")
            .stringType()
            .noDefaultValue()
            .withDescription("ScyllaDB 键空间（数据库）名称");

    public static final ConfigOption<String> TABLE_NAME = ConfigOptions
            .key("table-name")
            .stringType()
            .noDefaultValue()
            .withDescription("ScyllaDB 表名");

    public static final ConfigOption<String> USERNAME = ConfigOptions
            .key("username")
            .stringType()
            .noDefaultValue()
            .withDescription("ScyllaDB 用户名");

    public static final ConfigOption<String> PASSWORD = ConfigOptions
            .key("password")
            .stringType()
            .noDefaultValue()
            .withDescription("ScyllaDB 密码");

    // 扫描相关配置
    public static final ConfigOption<Integer> SCAN_FETCH_SIZE = ConfigOptions
            .key("scan.fetch-size")
            .intType()
            .defaultValue(1000)
            .withDescription("扫描时每次批量获取的记录数");

    public static final ConfigOption<String> SCAN_PARTITION_COLUMN = ConfigOptions
            .key("scan.partition.column")
            .stringType()
            .noDefaultValue()
            .withDescription("用于分区扫描的列名");

    public static final ConfigOption<Integer> SCAN_PARALLELISM = ConfigOptions
            .key("scan.parallelism")
            .intType()
            .defaultValue(1)
            .withDescription("扫描并行度");

    // 查找相关配置
    public static final ConfigOption<Long> LOOKUP_CACHE_MAX_ROWS = ConfigOptions
            .key("lookup.cache.max-rows")
            .longType()
            .defaultValue(10000L)
            .withDescription("查找缓存最大行数");

    public static final ConfigOption<Duration> LOOKUP_CACHE_TTL = ConfigOptions
            .key("lookup.cache.ttl")
            .durationType()
            .defaultValue(Duration.ofMinutes(10))
            .withDescription("查找缓存生存时间");

    public static final ConfigOption<Integer> LOOKUP_MAX_RETRIES = ConfigOptions
            .key("lookup.max-retries")
            .intType()
            .defaultValue(3)
            .withDescription("查找失败最大重试次数");

    public static final ConfigOption<Boolean> LOOKUP_AGGREGATE_MODE = ConfigOptions
            .key("lookup.aggregate-mode")
            .booleanType()
            .defaultValue(false)
            .withDescription("是否启用聚合模式，将多条匹配记录聚合到一个数组字段中");

    public static final ConfigOption<String> LOOKUP_AGGREGATE_FIELD_NAME = ConfigOptions
            .key("lookup.aggregate-field-name")
            .stringType()
            .defaultValue("lookup_results")
            .withDescription("聚合模式下数组字段的名称");

    // 写入相关配置
    public static final ConfigOption<Integer> SINK_PARALLELISM = ConfigOptions
            .key("sink.parallelism")
            .intType()
            .defaultValue(1)
            .withDescription("写入并行度");

    public static final ConfigOption<Integer> SINK_BUFFER_FLUSH_MAX_ROWS = ConfigOptions
            .key("sink.buffer-flush.max-rows")
            .intType()
            .defaultValue(100)
            .withDescription("缓冲区刷新的最大行数");

    public static final ConfigOption<Duration> SINK_BUFFER_FLUSH_INTERVAL = ConfigOptions
            .key("sink.buffer-flush.interval")
            .durationType()
            .defaultValue(Duration.ofSeconds(1))
            .withDescription("缓冲区刷新间隔");

    public static final ConfigOption<Integer> SINK_MAX_RETRIES = ConfigOptions
            .key("sink.max-retries")
            .intType()
            .defaultValue(3)
            .withDescription("写入失败最大重试次数");

    public static final ConfigOption<String> SINK_APPEND_SET_FIELDS = ConfigOptions
            .key("sink.append-set-fields")
            .stringType()
            .defaultValue("")
            .withDescription("使用追加操作的 Set 字段名称，多个字段用逗号分隔（例如：event_name,tags）");

    // 连接池相关配置
    public static final ConfigOption<Integer> CONNECTION_POOL_LOCAL_SIZE = ConfigOptions
            .key("connection.pool.local-size")
            .intType()
            .defaultValue(1)
            .withDescription("本地数据中心连接池大小");

    public static final ConfigOption<Integer> CONNECTION_POOL_REMOTE_SIZE = ConfigOptions
            .key("connection.pool.remote-size")
            .intType()
            .defaultValue(1)
            .withDescription("远程数据中心连接池大小");

    public static final ConfigOption<Duration> CONNECTION_TIMEOUT = ConfigOptions
            .key("connection.timeout")
            .durationType()
            .defaultValue(Duration.ofSeconds(5))
            .withDescription("连接超时时间");

    public static final ConfigOption<Duration> REQUEST_TIMEOUT = ConfigOptions
            .key("request.timeout")
            .durationType()
            .defaultValue(Duration.ofSeconds(12))
            .withDescription("请求超时时间");

    // 一致性级别配置
    public static final ConfigOption<String> CONSISTENCY_LEVEL = ConfigOptions
            .key("consistency.level")
            .stringType()
            .defaultValue("QUORUM")
            .withDescription("读写一致性级别 (ONE, TWO, THREE, QUORUM, ALL, LOCAL_QUORUM, EACH_QUORUM, LOCAL_ONE)");

    // SSL 配置
    public static final ConfigOption<Boolean> SSL_ENABLED = ConfigOptions
            .key("ssl.enabled")
            .booleanType()
            .defaultValue(false)
            .withDescription("是否启用 SSL 连接");

    public static final ConfigOption<String> SSL_KEYSTORE_PATH = ConfigOptions
            .key("ssl.keystore.path")
            .stringType()
            .noDefaultValue()
            .withDescription("SSL 密钥存储路径");

    public static final ConfigOption<String> SSL_KEYSTORE_PASSWORD = ConfigOptions
            .key("ssl.keystore.password")
            .stringType()
            .noDefaultValue()
            .withDescription("SSL 密钥存储密码");

    public static final ConfigOption<String> SSL_TRUSTSTORE_PATH = ConfigOptions
            .key("ssl.truststore.path")
            .stringType()
            .noDefaultValue()
            .withDescription("SSL 信任存储路径");

    public static final ConfigOption<String> SSL_TRUSTSTORE_PASSWORD = ConfigOptions
            .key("ssl.truststore.password")
            .stringType()
            .noDefaultValue()
            .withDescription("SSL 信任存储密码");
} 